package farprt;

import java.sql.*;

public class JDBCFirstDemo {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");

        String url ="jdbc:mysql://localhost:3306/jdbctest?useUnicode=true&characterEncoding=utf8&useSSL=true";
        String username="root";
        String password="13122566";

        Connection connection = DriverManager.getConnection(url, username, password);

        Statement statement = connection.createStatement();

        String sql="select * from  user";

/*        statement.executeQuery(sql);//查询操作,返回resultset
        statement.execute(sql);//执行任何sql
        statement.executeUpdate(sql);//更新，插入，删除，返回受影响的行数*/

        ResultSet resultSet = statement.executeQuery(sql);//返回的结果集

/*        resultSet.beforeFirst();//移动到最前
        resultSet.afterLast();//移动到最后
        resultSet.next();//移动到下一个数据
        resultSet.previous();//移动到前一行
        resultSet.absolute(row);//移动到指定行*/

        while (resultSet.next()){
            System.out.println("id="+resultSet.getObject("id"));
            System.out.println("name="+resultSet.getObject("name"));
            System.out.println("password="+resultSet.getObject("password"));
        }

        resultSet.close();
        statement.close();
        connection.close();


    }
}
